<?php
header("content-type:text/html;charset=utf-8");
$act = $_REQUEST['act'];
$username = $_POST['username'];
$password = md5($_POST['password']);
// print_r($act);die;
mysql_connect("localhost","root","root");
mysql_select_db("imooc");
mysql_set_charset("utf8");

if($act == "reg"){
	// echo "reg";die;
	$sql = "insert user(username,password) values('{$username}','{$password}')";
	// echo $sql;
	$result = mysql_query($sql);
	if($result){
		echo "注册成功，3秒后跳转到登录页面";
		echo "<meta http-equiv='refresh' content='3;url=login.html'/>";
	}else{
		echo "注册失败，请重新注册";
		echo "<meta http-equiv='refresh' content='3;url=reg.html'/>";
	}
}elseif($act == "login"){
	// echo "login";die;
	$sql = "select *from user where username='{$username}' and password='{$password}' ";
	$result = mysql_query($sql);
	$row = mysql_fetch_assoc($result);
	// print_r($row);
	if($row){
		echo "登录成功，3秒后跳转到首页";
		echo "<meta http-equiv='refresh' content='3;url=http://www.imooc.com'/>";
		
	}else{
		echo "登录失败，请重新登录";
		echo "<meta http-equiv='refresh' content='3;url=login.html'/>";
		
	}
}